package com.jz.community.basecomm.utils;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;

import com.alibaba.android.arouter.launcher.ARouter;
import com.jz.community.basecomm.routerUtils.RouterIntentConstant;

/**
 * Created by Admin on 2018/3/30 0030.
 */

public class BaseUserUtils {


    public static boolean getIsLogin(Context context) {
        return BaseSpUtils.getInstance().getIsLogin(context);
    }

    public void setIsLogin(Context context, boolean isLogin) {
        BaseSpUtils.getInstance().setIsLogin(context, isLogin);
    }

    /**
     * 登录提示无弹窗
     *
     * @param context
     * @return
     */
    public static boolean showIsLoginDialog(Context context) {
        if (!getIsLogin(context)) {
            WpToast.l(context, "你还未登录，请先登录！");
            ARouter.getInstance().build(RouterIntentConstant.MODULE_AUTHORIZATION_LOGIN).navigation();
            return false;
        } else {
            return true;
        }
    }

    /**
     * 登录提示弹窗
     *
     * @param context
     * @param isShowDialog
     * @return
     */
    public static boolean showIsLoginDialog(Context context, boolean isShowDialog) {
        if (!getIsLogin(context) && isShowDialog) {
            AlertDialog alertDialog = new AlertDialog.Builder(context).setMessage("提示")
                    .setMessage("需要登录才能继续操作，是否现在登录？")
                    .setNegativeButton("取消", null)
                    .setPositiveButton("登录", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            ARouter.getInstance().build(RouterIntentConstant.MODULE_AUTHORIZATION_LOGIN).navigation();
                        }
                    }).show();
            alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setTextColor(Color.RED);
            alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).setTextColor(Color.BLACK);
            return false;
        } else {
            return true;
        }
    }
}
